package com.orange.lswidget.widgets.event.manager;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.net.Uri;
import android.provider.BaseColumns;
import android.view.View;
import android.widget.RemoteViews;

import com.orange.lswidget.R;
import com.orange.notificationsummary.utils.Constants;
import com.orange.notificationsummary.utils.EventLSWidgetUtils;
import com.orange.util.LSEventUtils;

public abstract class EventManager implements BaseColumns {
	private static String		TAG							= "EventManager";

	public static final Uri		CONTENT_URI					= Uri.parse("content://"
																	+ Constants.AUTHORITY
																	+ "/notification");

	public static final String	COLUMN_NOTIFICATION_COUNT	= "sumCount";
	// addb by gaoge 2011-08-19 for fix bug 0013239
	public static final String	COLUMN_UNREADMMS_COUNT		= "unreadmms_count";
	public static final String	COLUMN_MISSCALL_COUNT		= "misscall_count";
	public static final String	COLUMN_VOICEMAI_COUNT		= "voicemail_count";

	protected boolean			mIsVip;
	protected int				mCount;
	protected String			mTime;
	protected String			mFrom;
	protected String			mNumberLabel;
	protected int				mNumberCountByContact;

	protected Bitmap			mBitmap;
	protected int				mBasicIconResId;
	protected String			mBasicTypeString;
	protected int				mDetailedIconResId;
	protected String			mDetailedTypeString;
	protected long				mLastEventTime;
	protected int				mType;

	protected Context			mContext;
	protected List<String>		mNames						= new ArrayList<String>();

	public EventManager(Context context) {
		mContext = context;
	}

	public RemoteViews getSummaryView(RemoteViews remoteViews,
			boolean isDisplayTime) {
		RemoteViews temprRemoteViews = remoteViews;
		if (mCount <= 0) {
			return temprRemoteViews;
		}

		temprRemoteViews.setImageViewResource(R.id.event_basic_icon,
				mBasicIconResId);
		temprRemoteViews.setTextViewText(R.id.event_basic_count,
				String.valueOf(mCount));
		if (mCount == 1) {
			temprRemoteViews = getEventTimeViews(temprRemoteViews,
					isDisplayTime);
		}

		temprRemoteViews.setTextViewText(R.id.event_basic_type,
				mBasicTypeString);

		if (EventLSWidgetUtils.getEventPreviewSetting(mContext)) {
			temprRemoteViews.setViewVisibility(R.id.event_basic_contacts,
					View.GONE);
		} else {
			temprRemoteViews.setViewVisibility(R.id.event_basic_contacts,
					View.VISIBLE);
			temprRemoteViews.setTextViewText(R.id.event_basic_contacts,
					LSEventUtils.getNameString(mContext, mNames));
		}

		return temprRemoteViews;
	}

	private RemoteViews getEventTimeViews(RemoteViews remoteViews,
			boolean isDisplayTime) {
		if (isDisplayTime) {
			remoteViews.setViewVisibility(R.id.event_detailed_time,
					View.VISIBLE);
			remoteViews.setTextViewText(R.id.event_detailed_time, mTime);
			remoteViews.setFloat(R.id.event_basic_contacts, "setTextSize",
					16.0f);
		} else {
			remoteViews.setViewVisibility(R.id.event_detailed_time, View.GONE);
		}

		return remoteViews;
	}

	public long getLastEventTime() {
		return mLastEventTime;
	}

	public int getEventType() {
		return mType;
	}

	public int getCount() {
		return mCount;
	}

	protected abstract void setCount();

	protected abstract void updateDetailedInfo();

	public abstract void updateSummaryInfo();

	protected abstract RemoteViews getDetailedView(RemoteViews remoteViews);
}
